package com.babyqiao.wallpaper.portal.controller;

import com.babyqiao.wallpaper.portal.service.UmsMemberService;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.common.domain.UserDto;
import com.macro.mall.model.UmsMember;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 微信小程序用户相关接口
 *
 * @author QLZ
 * @date 2021/1/1
 */
@RestController
@RequestMapping("/sso/wxprogram")
@Api(tags = "微信小程序用户相关接口")
public class UmsOtherLoginController {

//    @Autowired
//    private WxMiniProgramService wxMiniProgramService;
    @Autowired
    private UmsMemberService memberService;


    /**
     * 微信小程序登录应用
     *
     * @param code:
     * @Author QLZ
     * @Date 2021/1/1
     * @return: com.babyqiao.wallpaper.common.UnifyResult
     */

    @GetMapping("/login/{code}")
    @ApiOperation(value = "微信小程序登录")
    public CommonResult login(@PathVariable String code) throws Exception {

        //String s = wxMiniProgramService.loginService(code);
        return memberService.loginBywxMiniProgramService(code);

    }

    //@ApiOperation("根据用openid获取通用用户信息")
    @ApiIgnore
    @RequestMapping(value = "/loadByOpenid", method = RequestMethod.GET)
    @ResponseBody
    public UserDto loadUserByUsername(@RequestParam String openid) {
        return memberService.loadUserByOpenid(openid);
    }

    @ApiOperation("获取会员信息")
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult info() {
        UmsMember member = memberService.getCurrentMember();
        return CommonResult.success(member);
    }



}
